package com.emip.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.emip.bean.AlterLogBean;
import com.emip.dao.AlterLogDAO;
import com.emip.dao.BaseDAO;


@Repository("alterLogDAO")
public class AlterLogDAOImpl extends BaseDAO implements AlterLogDAO {

	public AlterLogBean merge(AlterLogBean log) {
		return getHibernateTemplate().merge(log);
	}

	@SuppressWarnings("unchecked")
	public List<AlterLogBean> findByDate(String startDate, String endDate, String type, String flag) {
		String hql = "from AlterLogBean al where al.genTime >= 'to_date(" + 
				startDate + ", 'yyyy-mm-dd') and al.genTime <= to_date(" + 
				endDate + ", 'yyyy-mm-dd')";
		if (type != null) {
			hql += " and type = '" + type + "'";
		}
		if (flag != null) {
			hql += " and flag = '" + flag + "'";
		}
		return getHibernateTemplate().find(hql);
	}
	
	@SuppressWarnings("unchecked")
	public List<AlterLogBean> getAll(String type, String flag) {
		String hql = "from AlterLogBean al where 1=1 ";
		if (type != null) {
			hql += " and type='" + type + "'";
		}
		if (flag != null) {
			hql += " and flag = '" + flag + "'";
		}
		return getHibernateTemplate().find(hql + " order by al.date, al.site.id, al.item.id");
	}

}
